const app = getApp()
// pages/user/user.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: false,
    articleNum: '',
    collectNum: '',
    zanNum: '',
    userInfo: {},

  },
  // 去用户资料
  goProfile() {
    wx.navigateTo({
      url: '/pkgUser/pages/profile/profile'
    })
  },
  // 去登录
  goLogin() {
    wx.redirectTo({
      url: '/pkgUser/pages/login/login'
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    // this.getTabBar获取自定义tabBar组件实例，设置对应显示高亮
    this.getTabBar().setData({ selected: 3 })
    this.setData({ isLogin: Boolean(app.token) })
    // 获取用户信息
    this.getUserInfo()

  },
  async getUserInfo() {
    const res = await wx.http.get('/user/getUserInfo')
    this.setData({
      articleNum: res.data.articleNum,
      collectNum: res.data.collectNum,
      zanNum: res.data.zanNum,
      userInfo: res.data.userInfo
    })
    console.log(res.data.userInfo)
    app.userProfiles = res.data.userInfo
    console.log(this.data.userInfo.icon)
  },
  layout() {
    console.log(11)
    app.removeToken()
    this.setData({ isLogin: false })
  }
})